﻿@using Covenant.Models.Listeners
@model HttpListener
@{
    IEnumerable<HttpProfile> Profiles = ViewBag.Profiles;
    IEnumerable<HostedFile> HostedFiles = ViewBag.HostedFiles;
}

<ul class="nav nav-tabs mb-3" id="listener-tab" role="tablist">
    <li class="nav-item">
        <a class="nav-link active" id="info-tab" data-toggle="tab" href="#info" role="tab" aria-controls="info" aria-selected="true">
            <span data-feather="info"></span>
            Info
        </a>
    </li>
    <li class="nav-item">
        <a class="nav-link" id="host-tab" data-toggle="tab" href="#host" role="tab" aria-controls="host" aria-selected="false">
            <span data-feather="cloud"></span>
            Hosted Files
        </a>
    </li>
</ul>

<div class="tab-content" id="listener-tab-content">
    <div class="tab-pane fade" id="info" role="tabpanel" aria-labelledby="info-tab">
        <input asp-for="Id" value="@Model.Id" type="hidden" disabled>
        <input asp-for="GUID" value="@Model.GUID" type="hidden" disabled>
        <input asp-for="ListenerTypeId" value="@Model.ListenerTypeId" type="hidden" disabled>
        <input asp-for="Status" value="Active" type="hidden" disabled>
        <input asp-for="CovenantToken" value="@Model.CovenantToken" type="hidden" disabled>
        <div class="form-group">
            <label asp-for="Description"></label>
            <input asp-for="Description" value="@Model.Description" class="form-control-plaintext" readonly disabled>
        </div>
        <div class="form-group">
            <label asp-for="Name"></label>
            <input asp-for="Name" value="@Model.Name" class="form-control" disabled>
        </div>
        <div class="form-row">
            <div class="form-group col-md-4">
                <label asp-for="BindAddress"></label>
                <input asp-for="BindAddress" value="@Model.BindAddress" class="form-control form-control" disabled>
            </div>
            <div class="form-group col-md-4">
                <label asp-for="BindPort"></label>
                <input asp-for="BindPort" value="@Model.BindPort" class="form-control form-control" disabled>
            </div>
        </div>
        <div class="form-row">
            <div class="form-group col-md-3">
                <label asp-for="ConnectPort"></label>
                <input asp-for="ConnectPort" value="@Model.ConnectPort" class="form-control form-control" disabled>
            </div>
        </div>
        <div class="d-flex flex-row address-row">
            <div class="form-group col-md-4 pl-0 mt-1 mb-1">
                <label asp-for="ConnectAddresses[0]">ConnectAddress</label>
                <input asp-for="ConnectAddresses[0]" value="@Model.ConnectAddresses[0]" class="form-control address" disabled>
            </div>
            <div class="form-group col-md-4 pl-0 mt-1 mb-1">
                <label asp-for="Urls[0]">Url</label>
                <input asp-for="Urls[0]" value="@Model.Urls[0]" class="form-control" disabled>
            </div>
        </div>
        @for (int i = 1; i < Model.ConnectAddresses.Count; i++)
        {
            <div class="d-flex flex-row address-row">
                <div class="form-group col-md-4 pl-0 mt-1 mb-1">
                    <input asp-for="ConnectAddresses[i]" value="@Model.ConnectAddresses[i]" class="form-control address" disabled>
                </div>
                <div class="form-group col-md-4 pl-0 mt-1 mb-1">
                    <input asp-for="Urls[i]" value="@Model.Urls[i]" class="form-control url" disabled>
                </div>
            </div>
        }
        <div class="form-row">
            <div class="form-group col-md-3">
                <label asp-for="UseSSL"></label>
                <select asp-for="UseSSL" class="form-control form-control-sm" disabled>
                    <option>@Model.UseSSL.ToString()</option>
                </select>
            </div>
            <div class="form-group col-md-6">
                <label asp-for="SSLCertificatePassword"></label>
                <input asp-for="SSLCertificatePassword" class="form-control form-control-sm" disabled>
            </div>
        </div>
        <div class="form-group">
            <label asp-for="ProfileId">HttpProfile</label>
            <select asp-for="ProfileId" class="form-control" disabled>
                <option>@Model.Profile.Name</option>
            </select>
        </div>

        <div class="btn-group" role="group">
            @if (Model.Status == ListenerStatus.Active)
            {
                <form asp-action="Stop" asp-route-id="@Model.Id">
                    <button type="submit" class="btn btn-warning"><span data-feather="stop-circle"></span> Stop</button>
                </form>
            }
            else
            {
                <form asp-action="Start" asp-route-id="@Model.Id">
                    <button type="submit" class="btn btn-primary"><span data-feather="play"></span> Start</button>
                </form>
            }
            <form asp-action="Delete" asp-route-id="@Model.Id">
                <button type="submit" class="btn btn-danger ml-2"><span data-feather="x"></span> Delete</button>
            </form>
        </div>
    </div>
    <div class="tab-pane fade" id="host" role="tabpanel" aria-labelledby="host-tab">
        @{
            ViewBag.Listener = Model;
            await Html.RenderPartialAsync("../HostedFile/_HostedFileTable", HostedFiles);
        }
    </div>
</div>